package org.mindrive.system.service.upgrade.execute;

import java.util.concurrent.ConcurrentHashMap;

public class UpgradeExecute {

	private String version = "";

	private static ConcurrentHashMap<String, UpgradeProvider> providers = new ConcurrentHashMap<String, UpgradeProvider>();

	public static void registerProvider(UpgradeProvider provider) {
		providers.put(provider.getVersion(), provider);
	}

	public static UpgradeProvider getProvider(String version) {
		UpgradeProvider provider = providers.get(version);
		if (provider == null) {
			throw new IllegalStateException("没有找到" + version + "的升级程序");
		}
		return provider;
	}

	public UpgradeExecute(String version) {
		this.version = version;
	}

	public void execute() {
		UpgradeProvider provider = getProvider(this.version);
		provider.execute();
	}
}
